package fr.aprr.odyssee.server;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import fr.aprr.odyssee.client.GreetingService;
import fr.aprr.odyssee.server.domain.dao.OngletDAO;
import fr.aprr.odyssee.server.domain.entities.Odyssee;
import fr.aprr.odyssee.server.domain.entities.VehiculeFamille;
import fr.aprr.odyssee.shared.FieldVerifier;

@Service("greetService")
public class SpringServiceImpl extends RemoteServiceServlet implements
		GreetingService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	private OngletDAO ongletDao;

	@Override
	public String greetServer(String name) throws IllegalArgumentException {
		// TODO Auto-generated method stub

		if (!FieldVerifier.isValidName(name)) {
			throw new IllegalArgumentException(
					"Name must be at least 4 characters long");
		}
		
		List<Odyssee> list = ongletDao.getAllArticle();
		//addTest();

		return "Name must be at least 4 characters long : " + list.get(2).getNomChamp();
	}
	
	public void addTest(){
		Odyssee a = new Odyssee(27, "AA", "BB", "CC");
		ongletDao.addOnglet(a);
	}
	public OngletDAO getOngletDao() {
		return ongletDao;
	}

	public void setOngletDao(OngletDAO ongletDao) {
		this.ongletDao = ongletDao;
	}

	

}
